package io.github.jast90.internship.util;

import io.github.jast90.internship.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
 * Created by jast90 on 2021/3/12
 */
@Service
public class SessionUtil {

    @Autowired
    private HttpSession session;

    public long getUid(){
        User user = (User) session.getAttribute("s_sysUser");
        return user.getId();
    }

    public boolean admin(){
        User user = (User) session.getAttribute("s_sysUser");
        return user.getUserType()==1;
    }

    public boolean teacher(){
        User user = (User) session.getAttribute("s_sysUser");
        return user.getUserType()==2;
    }

    public boolean student(){
        User user = (User) session.getAttribute("s_sysUser");
        return user.getUserType()==3;
    }
}
